package band.wukong.practice.javase.core.thread.sync;

/**
 * Desc: 同步静态方法
 * Author: sunjs
 * Date: 2009-11-6 11:08:44
 */
public class TestSynStaticMethod implements Runnable {
    private static int a = 1;

    public synchronized static void go(int i) {
        a += i;
        Thread.yield();
        a -= i;
        System.out.println("a = " + a);
    }

    public void run() {
        for (int i = 0; i < 1000; i++) {
            go(i);
        }
    }

    public static void main(String[] args) {
        TestSynStaticMethod m = new TestSynStaticMethod();
        Thread t1 = new Thread(m);
        Thread t2 = new Thread(m);
        t1.start();
        t2.start();
    }
}
